package jwtMinddle

import ()

/*
默認忽略
*/
var JwtIgnore *JwtIgnorePath

func init() {
	if JwtIgnore == nil {
		JwtIgnore = NewJwtIgnorePath()
	}
	JwtIgnore.AddKey("/public")
	JwtIgnore.AddKey("/")

}

type JwtIgnorePath struct {
	pre        *entity.HashSet[string]
	IgnorePath map[string]*entity.HashSet[string]
}

func NewJwtIgnorePath() *JwtIgnorePath {
	//entity.NewHashSet[string]()
	return &JwtIgnorePath{
		pre:        entity.NewHashSet[string](),
		IgnorePath: make(map[string]*entity.HashSet[string]),
	}
}
func (p *JwtIgnorePath) AddKey(pre string, key ...string) {
	p.pre.Add(pre)
	if len(key) <= 0 {
		_, ok := p.IgnorePath[pre]
		if !ok {
			p.IgnorePath[pre] = entity.NewHashSet[string]()
		}
		p.IgnorePath[pre].Add(key...)
	}

}
func (p *JwtIgnorePath) AddRootKey(key ...string) {
	p.pre.Add("/")
	_, ok := p.IgnorePath["/"]
	if !ok {
		p.IgnorePath["/"] = entity.NewHashSet[string]()
	}
	p.IgnorePath["/"].Add(key...)

}
func (p *JwtIgnorePath) Contain(pre, key string) bool {
	if !p.pre.Contain(pre) {
		return false
	}
	return p.IgnorePath[pre].Contain(key)
}
func (p *JwtIgnorePath) ContainPre(pre string) bool {
	return p.pre.Contain(pre)

}
